home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 1 / Precision Software Applications Silver Collection Volume One (PSM) (1993).iso / demos / devel3.exe / MATHINIT.C < prev    next >
C/C++ Source or Header  |  1992-05-17  |  1KB  |  64 lines

  1. /* Routines to initialize math tables for greater speed later on.
  2.    Part of the REND386 package by Dave Stampe and Bernie Roehl.
  3.  */
  4.  
  5. /* Copyright 1992 by Dave Stampe and Bernie Roehl.
  6.    May be freely used to write software for release into the public domain;
  7.    all commercial endeavours MUST contact Bernie Roehl and Dave Stampe
  8.    for permission to incorporate any part of this software into their
  9.    products!
  10.  */
  11.  
  12. #include <stdlib.h>
  13. #include <math.h>
  14.  
  15. /* this stuff moved out of integer core so that there are
  16.    no uncompilable TC references in integer core library */
  17.  
  18. #define XFSC 536870912   /* 2**29 for shifting xform coeffs to long */
  19. static float xfsc = XFSC;
  20.  
  21. long sintable[258];
  22.  
  23. fill_sine()
  24.     {
  25.     int i;
  26.  
  27.     for (i = 0; i < 256; i++)
  28.         sintable[i] = (XFSC * sin(3.14159/2/256 * i));
  29.     sintable[256] = XFSC;
  30.     sintable[257] = XFSC;
  31.     return 0;
  32.     }
  33.  
  34.         /* tables for sphere object clipping:   */
  35. long sclip_C[800];    /* 1/sqrt(zoom^2 + 1) table           */
  36. long sclip_M[800];    /* zoom * C table  (table: i = 32*zoom) */
  37.         /* range: FOV = 2*atan(1/zoom)          */
  38.         /* or about 150 to 7 degrees         */
  39. fill_sclip()
  40.     {
  41.     int i;
  42.     float n;
  43.  
  44.     for (i = 0; i < 800; i++)
  45.         {
  46.         n = 1.0/sqrt((i/16.0)*(i/16.0) + 1);
  47.         sclip_C[i] = XFSC * n;
  48.         sclip_M[i] = XFSC * ((i/16.0) * n) ;
  49.         }
  50.         return 0;
  51.     }
  52.  
  53. int sqrtable[1024];
  54.  
  55. fill_sqrt()
  56.     {
  57.     int i;
  58.  
  59.     for (i = 0; i < 1024; i++)
  60.         sqrtable[i] = 1024*sqrt(i);
  61.     return 0;
  62.     }
  63.  
  64.